package com.jianjun.project.monitor.logininfor;

import com.jfinal.aop.Before;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.jianjun.project.common.model.SysLogininfor;

import java.util.List;

/**
 * 系统访问日志情况信息 服务层处理
 *
 * @author source
 */

public class SysLogininforService {
    private final SysLogininfor dao = new SysLogininfor().dao();

    public Page<SysLogininfor> paginate(SysLogininfor model) {
        SqlPara sqlParaDb = Db.getSqlPara("querySysLogininfor", Kv.by("cond", model.toMap()).set(model.getColumnAsc()));
        return dao.paginate(model.getPageNum(), model.getPageSize(), sqlParaDb);
    }

    public List<SysLogininfor> selectLogininforList(Model<SysLogininfor> model) {
        SqlPara sqlParaDb = Db.getSqlPara("querySysLogininfor", Kv.by("cond", model.toMap()));
        return dao.find(sqlParaDb);
    }

    @Before(Tx.class)
    public boolean deleteLogininforByIds(Long[] ids) {
        for (Long id : ids) {
            dao.deleteById(id);
        }
        return true;
    }

    public void cleanLogininfor() {
        Db.template("deleteLoginnfor").update();
    }
}
